<?php

class User extends AppModel{
    
    public $belongsTo = array(
        'Image' => array(
            'foreignKey' => 'images_id'
        )
    );
    
    public $hasOne = array(
        'UserGroup' => array(
            'foreignKey' => 'users_id'
        ),
        'UserAdmin' => array(
            'foreignKey' => 'users_id'
        )
    );
    
    public $hasMany = array(
        'UserTopicGroup' => array(
            'foreignKey' => 'users_id'
        )
    );
    
    public function getUser($type, $options = array()){
        $user = $this->find($type, $options);
        
        
        if (isset($user['UserGroup']) && $user['UserGroup']['id'] == null){
            $user['UserGroup'] = false;
        }
        if (isset($user['UserAdmin']) && $user['UserAdmin']['users_id'] == null){
            $user['UserAdmin'] = false;
        }
        return $user;
    }
    
    function beforeSave($options = array()) {
        if(!empty($this->data['User']['password']))
            $this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);
        return true;
    }
}
?>
